import { Friendship, Wechaty as WechatyType } from '_wechaty@0.60.12@wechaty'
import {config} from './config/config'
async function onFriendShip(this:WechatyType,friendship:Friendship) {
  try {
    const contact = friendship.contact()
    const webRoom = await this.Room.find({
      topic: config.inviteRoom[0],
    })

    switch (friendship.type()) {
      case this.Friendship.Type.Receive:
        await friendship.accept()
        await contact.say(config.template)
        await webRoom?.add(contact)
        break
      case this.Friendship.Type.Confirm:
        break
    }
  } catch (e) {
    console.error(e)
  }
}
export default onFriendShip
